package com.egao.common.manage.college;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.core.web.PageParam;
import com.egao.common.core.web.PageResult;
import com.egao.common.module.student.entity.StudentBasic;
import com.egao.common.module.student.service.StudentBasicService;
import com.egao.common.module.student.service.StudentService;
import com.egao.common.module.system.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 院基层就业管理
 * @author lsh
 */
@Api(tags = "院基层就业管理")
@RestController
@RequestMapping("${api}")
public class CollegeBasicContrller extends BaseController {

    @Autowired
    private StudentBasicService basicService;

    @Autowired
    private StudentService studentService;

    @PreAuthorize("hasAuthority('college')")
    @ApiOperation(value = "院基层就业管理列表")
    @ApiPageParam
    @GetMapping("/college/basic/list")
    public PageResult<StudentBasic> basicPage(HttpServletRequest request) {
        String collegeCode = getLoginUser().getCollegeCode();
        PageParam<StudentBasic> pageParam = new PageParam<>(request);
        Map<String, Object> pageData = pageParam.getPageData();
        pageData.put("collegeCode", collegeCode);
        pageParam.setPageData(pageData);
        return new PageResult<>(basicService.listPage(pageParam), pageParam.getTotal());
    }

    @PreAuthorize("hasAuthority('college')")
    @ApiOperation(value = "院基层就业填报详情")
    @ApiPageParam
    @GetMapping("/college/basic/detail")
    public JsonResult basicdetail(Integer id) {
        if (id == null) {
            return JsonResult.error("传入参数异常");
        }
        return JsonResult.ok().setData(basicService.BasicDetailSchool(id));
    }

    @PreAuthorize("hasAuthority('college')")
    @ApiOperation(value = "院基层就业填报审批")
    @ApiPageParam
    @PutMapping("/college/basic/submit")
    public JsonResult basicSave(@RequestBody StudentBasic studentBasic) {
        if (studentBasic == null) {
            return JsonResult.error("传入参数异常");
        }
        boolean save = basicService.updateById(studentBasic);
        if (save){
            return JsonResult.ok();
        }
        return JsonResult.error("服务器异常，请联系管理人员！");
    }

}
